<?php
/**
 * Created by IntelliJ IDEA.
 * User: XingHuo
 * Date: 15/4/25
 * Time: 下午10:58
 */

class CommonHelper {
    static function formatServerList($servers,$onlyId=false){
        $listSer = $list = array();
        foreach($servers as $server){
            $listSer['id'] =  'server='.$server['host'].':'.$server['port'].';';
            if (!$onlyId) {
                $listSer['name'] =  $server['host'].':'.$server['port'];
                $list[] = $listSer;
            }else{
                $list[] = $listSer['id'];

            }
        }
        return $list;
    }
    static function parseNodeName($nodeName){

        $explode = str_replace(';','&', $nodeName);
        parse_str($explode,$query);
        return array(
            Boot::get($query,'server',''),
            Boot::get($query,'db',''),
            Boot::get($query,'collection','')
        );
    }

    /**
     * @param $cl MongoCollection
     * @return MongoCollection
     */
    static function  getCollectionName($cl){
        return 'collection='.$cl->getName().'';
    }
    static function  getDbName($db){
        return 'db='.Boot::get($db,'name','').';';
    }
}